ROOT := .

SUBDIR := $(ROOT)
SUBDIR += $(ROOT)/func

TARGET := main
OUTPUT := $(ROOT)/output
FLAGS  += -Wall

INCS := $(foreach dir,$(SUBDIR),-I$(dir))
SRCS := $(foreach dir,$(SUBDIR),$(wildcard $(dir)/*.c))
OBJS := $(patsubst %.c,$(OUTPUT)/%.o, $(SRCS))
DEPS := $(patsubst %.o,%.d,$(OBJS))

$(TARGET):$(OBJS)
	@echo linking...
	@gcc $(FLAGS) $(OBJS) -o $@
	@echo link complete!
	
$(OUTPUT)/%.o:%.c
	@echo compile $<...
	@mkdir -p $(dir $@)
	@gcc $(FLAGS) -MMD -MP -c $(INCS) $< -o $@
	
.PHONY:clean

clean:
	@echo try to clean
	@rm -rf $(OUTPUT)
	@echo clean complete!
	
-include $(DEPS)






